package com.itheima.app.controller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.MessageManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.PartialUpdate;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class MessageController {

    @Autowired
    private MessageManager messageManager;

    // 获取环信的认证信息
    @GetMapping("/huanxin/user")
    public ResponseEntity findHuanxinUser() {
        // 1.获取登录用户id
        Long userId = UserHolder.get().getId();

        // 2.封装返回结果
        Map<String, String> map = new HashMap<>();
        map.put("username", userId.toString());
        map.put("password", "123456");

        return ResponseEntity.ok(map);
    }

    // 打招呼（向陌生人发送一条消息）
    @PostMapping("/tanhua/strangerQuestions")
    public ResponseEntity sendStrangerQuestions(@RequestBody Map<String, String> map) {
        // 接收参数
        String jiarenId = map.get("userId");
        String reply = map.get("reply");
        // 调用manager
        return messageManager.sendStrangerQuestions(jiarenId, reply);
    }

    // 聊一下（添加好友）
    @PostMapping("/messages/contacts")
    public ResponseEntity addContacts(@RequestBody Map<String, Long> map) {
        // 接收参数
        Long friendId = map.get("userId");
        // 调用manager
        return messageManager.addContacts(friendId);
    }

    // 查询好友列表
    @GetMapping("/messages/contacts")
    public ResponseEntity findContacts(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "8") Integer pageSize) {
        // 调用manager
        return messageManager.findContacts(pageNum,pageSize);
    }


    // 查看对你点赞用户列表
    @GetMapping("messages/likes")
    public ResponseEntity likes(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "8") Integer pageSize) {
        // 确定类型
        Integer commentType=1;
        // 调用manager
        return messageManager.findComment(pageNum,pageSize,commentType);
    }

    // 查看对你评论用户列表
    @GetMapping("messages/comments")
    public ResponseEntity comments(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "8") Integer pageSize) {
        // 确定类型
        Integer commentType=2;
        // 调用manager
        return messageManager.findComment(pageNum,pageSize,commentType);
    }

    // 查看对你喜欢用户列表
    @GetMapping("messages/loves")
    public ResponseEntity loves(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "8") Integer pageSize) {
        // 确定类型
        Integer commentType=3;
        // 调用manager
        return messageManager.findComment(pageNum,pageSize,commentType);
    }
}
